#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"
#include <math.h>

#define DEBUG 0 
#define NOISY_TEST 1

int test_steward(int card, int choice1, int choice2, int choice3, struct gameState *post, int handPos, int bonus) {
   struct gameState pre;
   memcpy (&pre, post, sizeof(struct gameState));
   int currentPlayer = whoseTurn(&pre), cardDrawn, drawntreasure = 0;
   int r, z = 0, temphand[MAX_HAND];
   r = cardEffect(card, choice1, choice2, choice3, post, handPos, &bonus);
   //code that changes the gamestate in the same way as the steward card.
   if (choice1 == 1){
      drawCard(currentPlayer, &pre);
      drawCard(currentPlayer, &pre);
   }
   else if (choice1 == 2){
      pre.coins = pre.coins + 2;
   }
   else{
      discardCard(choice2, currentPlayer, &pre, 1);
      discardCard(choice3, currentPlayer, &pre, 1);
   }
   discardCard(handPos, currentPlayer, &pre, 0);

   assert (r == 0);
   assert(memcmp(&pre, post, sizeof(struct gameState)) == 0);
}

int main () {

  int i, n, r, p, deckCount, discardCount, handCount;
  int bonus, handPos;
  int k[10] = {adventurer, council_room, feast, gardens, mine,
	       remodel, smithy, village, baron, great_hall};
  int card = steward, choice1, choice2, choice3;
  
  choice1 = 1;
  choice2 = 2;
  choice3 = 3;
  struct gameState G;

  printf ("Testing Steward card.\n");

  printf ("RANDOM TESTS.\n");
  SelectStream(2);
  PutSeed(3);

  for (n = 0; n < 2000; n++) {
     initializeGame(2, k, 2, &G);
     p = floor(Random() * 2);
     choice1 = n % 3;
     G.numPlayers = 2;
     G.whoseTurn =  floor(Random() * G.numPlayers);
     G.deckCount[p] = floor(Random() * MAX_DECK);
     G.discardCount[p] = floor(Random() * MAX_DECK);
     G.handCount[p] = floor(Random() * MAX_HAND);
     choice2 = floor(Random() * G.handCount[p]);
     choice3 = floor(Random() * G.handCount[p]);
     G.coins = floor(Random() * 10);
     test_steward(card, choice1, choice2, choice3, &G, handPos, bonus);
  }

  printf ("ALL TESTS OK\n");

/*
  printf ("SIMPLE FIXED TESTS.\n");
  for (p = 0; p < 2; p++) {
    for (deckCount = 0; deckCount < 5; deckCount++) {
      for (discardCount = 0; discardCount < 5; discardCount++) {
	for (handCount = 0; handCount < 5; handCount++) {
	  memset(&G, 23, sizeof(struct gameState)); 
	  r = initializeGame(2, k, 1, &G);
	  G.deckCount[p] = deckCount;
	  memset(G.deck[p], 0, sizeof(int) * deckCount);
	  G.discardCount[p] = discardCount;
	  memset(G.discard[p], 0, sizeof(int) * discardCount);
	  G.handCount[p] = handCount;
	  memset(G.hand[p], 0, sizeof(int) * handCount);
          test_adventurer(card, choice1, choice2, choice3, &G, handPos, bonus);
	}
      }
    }
  }
*/
  return 0;
}
